/*
 * @Description: 路由配置入口
 * @Author: hmt
 * @Date: 2022-08-17 10:24:19
 * @LastEditors: hmt
 * @LastEditTime: 2024-03-27 16:06:37
 */
import { createRouter, createWebHistory, RouteRecordRaw } from 'vue-router'

const modulesRoutes: Array<RouteRecordRaw> = []
const modulesFiles = require.context('./modules', false, /.+\.ts$/)

modulesFiles.keys().forEach((modulePath: string) => {
  const arr = modulesFiles(modulePath).default
  if (Array.isArray(arr)) modulesRoutes.push(...arr)
  else modulesRoutes.push(arr)
})


const routes: RouteRecordRaw[] = [
  {
    path: '/',
    redirect: '/search'
  },
  ...modulesRoutes,
  {
    path: '/:catchAll(.*)',
    redirect: '/404'
  }
]

const router = createRouter({
  history: createWebHistory(process.env.BASE_URL),
  routes
})

export default router
